import request from "@/utils/request";

export interface PrinterQuery extends PageQuery {
  page?: number;
  limit?: number;
  keywords?: string;
  type?: string;
}

export interface PrinterDetail {
  id: number;
  title: number;
  type: string;
  status: number;
  sn?: string;
  secret?: string;
}

export interface PrinterForm {
  id?: number;
  type?: number;
  shop_id?: number;
  title?: string;
  status?: number;
  sn?: string;
  secret?: string;
}

const baseUri = "/mv1/api/printer";

export function printerList(query: PrinterQuery) {
  return request({
    url: baseUri + "/",
    method: "get",
    params: query,
  });
}

export function printerDetail(id: number) {
  return request({
    url: baseUri + "/detail/" + id,
    method: "get",
    // params: {id},
  });
}

export function createPrinter(data: PrinterForm) {
  return request({
    url: baseUri + "/edit",
    method: "post",
    data: data,
  });
}

export function updatePrinter(id: number, data: PrinterForm) {
  return request({
    url: baseUri + "/edit/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 初始化打印机
 * @param id
 */
export function initPrinter(id: number) {
  return request({
    url: baseUri + "/init/" + id,
    method: "post",
  });
}

/**
 * 清空打印机
 * @param id
 */
export function clearPrinter(id: number) {
  return request({
    url: baseUri + "/clear/" + id,
    method: "post",
  });
}

export function deletePrinter(id: number) {
  return request({
    url: baseUri + "/" + id,
    method: "delete",
  });
}
